package com.demo.freemarker.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class Cp1Controller {
    private final Logger logger = LoggerFactory.getLogger(Cp1Controller.class);
    @RequestMapping("/cp1")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("cp1");
        mv.addObject("intVar", 100);
        mv.addObject("longVar", 10000L);
        mv.addObject("stringVar", "我是字符串");
        mv.addObject("doubleVar", 3.45);
        mv.addObject("booleanVar", true);
        mv.addObject("dateVar", new java.sql.Date(new Date().getTime()));
        mv.addObject("nullVar", null);
        Map<String, String> map = new HashMap<>();
        map.put("test", "test");
        map.put("test1", "test1");
        mv.addObject("map", map);
        return mv;
    }

    @RequestMapping("/string")
    public ModelAndView StringFun() {
        ModelAndView mv = new ModelAndView("string");
        return mv;
    }

    @RequestMapping("/sort")
    public ModelAndView Sort() {
        ModelAndView mv = new ModelAndView("sort");
        mv.addObject("sort_int", new SortMethod());
        return mv;
    }

    @RequestMapping("/command")
    public ModelAndView command() {
        ModelAndView mv = new ModelAndView("command");
        return mv;
    }

    @RequestMapping("/builtin")
    public ModelAndView builtin() {
        logger.info("内建函数");
        ModelAndView mv = new ModelAndView("builtin");
        return mv;
    }

    @RequestMapping("/macro")
    public ModelAndView macro() {
        logger.info("内建函数");
        ModelAndView mv = new ModelAndView("macro");
        return mv;
    }
}
